<html>
<head>
<title>prism.inc</title>
<style type="text/css">
<!--
pre{ font-family: "Courier New", Courier, monospace;
     background-color: #fafafa;
     border: 1px solid ; border-color: #000000;
     padding: 5pt;}

pre a:hover {background-color: #eeeeff;}

.med {color: #880088; font-weight: bold;}    /*Media*/
.func {color: #880088;}                      /*Functions (float, vector, string)*/
.mat {color: #880088; font-weight: bold;}    /*Materials*/
.squig {color: #0000dd;}                     /*{}*/
.cammod {color: #880088;}                    /*Camera modifiers*/
.glob {color: #880088; font-weight: bold;}   /*Global*/
.ident {font-weight: bold;}                  /*Identifiers*/
.obmod {color: #880088;}                     /*Object modifiers*/
.globmod {color: #880088;}                   /*Global modifiers*/
.dirc {color: #880088; font-weight: bold;}   /*Directives*/
.msg {color: #880088; font-weight: bold;}    /*Message streams*/
.atmo {color: #880088; font-weight: bold;}   /*Atmospheric objects*/
.matmod {color: #880088;}                    /*Material modifiers*/
.io {color: #880088; font-weight: bold;}     /*File I/O*/
.slcom {color: #009922; font-style: italic;} /*Single line comment*/
.obj {color: #880088; font-weight: bold;}    /*Objects*/
.mod {color: #880088;}                       /*Modifiers (general)*/
.inter {color: #880088; font-weight: bold;}  /*Interior*/
.atmod {color: #880088;}                     /*Atmospheric modifiers*/
.str {color: #ff0000;}                       /*Strings*/
.medmod {color: #880088;}                    /*Media modifiers*/
.num {color: #009999;}                       /*Numbers*/
.ptrn {color: #880088;}                      /*Patterns*/
.mlcom {color: #009922; font-style: italic;} /*Multi-line comment*/
.math {color: #ff0000;}                      /*Mathematical operators*/
.cam {color: #880088; font-weight: bold;}    /*Camera*/
.lite {color: #880088; font-weight: bold;}   /*Light source*/
.cond {color: #880088; font-weight: bold;}   /*Conditionals*/
.litmod {color: #880088;}                    /*Light modifiers*/
.dot {color: #880088;}                       /*Dot operators*/

-->
</style>
</head>
<body>
<p>prism.inc :</p>
<pre><span class="slcom">// Persistence of Vision Ray Tracer Scene Description File</span>
<span class="slcom">// File: prism.inc</span>
<span class="slcom">// Vers: 3.5</span>
<span class="slcom">// Desc: Macros to build a mesh2 prism (extrusion) object from a spline</span>
<span class="slcom">// Date: 2002/04/27</span>
<span class="slcom">// Auth: Ingo Janssen </span>

<span class="slcom">// revision 2002/08/28: replaced some ^ by pow() </span>

<span class="dirc">#version</span> <span class="num">3.5</span>;
<span class="dirc">#include</span> <span class="str">&quot;makemesh.inc&quot;</span>

<span class="mlcom">/*======
Prism(Spl, ResSpl, Height, HRes, FileName): Extrudes the spline along the y-axis.
           The uv_coordinates come from the square &lt;0,0&gt; - &lt;1,1&gt;.

Spl      : The spline to be extruded. 
           The spline is evaluated from t=0 to t=1. For the normal calculation,
           it is required that all splines (also linear_spline) have one extra
           point before t=0 and after t=1.
ResSpl   : The amount of triangles to be used along the spline
Height   : The amount of POV-units to extrude the shape.
HRes     : The amount of triangles to be used in the height.
FileName : The name of the file to whitch the mesh will be written. If is an
           empty string (&quot;&quot;), no file will be written.
           If the file extension is 'obj' a Wavefront objectfile will be written.
           If the extension is 'pcm' a compressed mesh file is written.
           If a file name is given, the macro will first check if it already exists.
           If that is so, it will try to parse the existing file unless it's a '*.obj',
           '*.pcm' or '*.arr' file as POV-Ray can not read them directly. In this case a new
           mesh will be generated, but the existing files will _not_ be over-written.
*/</span> 
<span class="dirc">#macro</span> <a name="Prism"><span class="ident">Prism</span></a>(Spl, ResSpl, Height, HRes, FileName)
   <span class="dirc">#local</span> __LinSpl<span class="math">=</span><span class="func">spline</span> <span class="squig">{</span>
      <span class="obmod">linear_spline</span>
      <span class="math">-</span><span class="num">1</span>,<span class="math">&lt;</span><span class="num">0</span>,<span class="math">-</span><span class="num">1</span>,<span class="num">0</span><span class="math">&gt;</span>
      <span class="num">1e-50</span>, <span class="math">&lt;</span><span class="num">0</span>,<span class="num">0</span>,<span class="num">0</span><span class="math">&gt;</span>
      <span class="num">1</span>,<span class="math">&lt;</span><span class="num">0</span>,Height,<span class="num">0</span><span class="math">&gt;</span>
      <span class="num">2</span>,<span class="math">&lt;</span><span class="num">0</span>,Height<span class="math">+</span><span class="num">1</span>,<span class="num">0</span><span class="math">&gt;</span>
   <span class="squig">}</span>
   Prism1(Spl, ResSpl, __LinSpl, HRes,FileName)
<span class="cond">#end</span>

<span class="mlcom">/*======
Prism1(Spl, ResSpl, PSpl, PRes, FileName): Extrudes the spline along the y-axis.
           In every step the spline is scaled by the 'relative' distance from the
           y-axis of the second spline (PSpl).
           The uv_coordinates come from the square &lt;0,0&gt; - &lt;1,1&gt;.

Spl      : The spline to be extruded.
           The spline is evaluated from t=0 to t=1. For the normal calculation,
           it is required that all splines (also linear_spline) have one extra
           point before t=0 and after t=1.
ResSpl   : The amount of triangles to be used along the spline.
PSpl     : The spline that determines by what amount the extrusion is scaled in
           each step. The scaling is based on the relative distance from the y-axis.
           That is, at t=0 the scale is always 1, so that the start of the shape is 
           identical to the spline Spl.
           PSpl also sets the height of the resulting shape (its y-value at t=1).
           The spline is evaluated from t=0 to t=1. For the normal calculation,
           it is required that all splines (also linear_spline) have one extra
           point before t=0 and after t=1.
FileName : The name of the file to whitch the mesh will be written. If is an empty
           string (&quot;&quot;), no file will be written. If a file name is given, the macro
	        will first check if it already exists. If that is so, it will expect a
	        mesh2 with the name &quot;Surface&quot; and try to parse the existing file.
*/</span>

<span class="dirc">#macro</span> <a name="Prism1"><span class="ident">Prism1</span></a>(Spl, ResSpl, PSpl, PRes, FileName)
   <span class="dirc">#declare</span> <a name="Build"><span class="ident">Build</span></a><span class="math">=</span>CheckFileName(FileName);
   <span class="cond">#if</span>(<a href="#Build">Build</a><span class="math">=</span><span class="num">0</span>)
      <span class="msg">#debug</span> <span class="func">concat</span>(<span class="str">&quot;\n Parsing mesh2 from file: &quot;</span>, FileName, <span class="str">&quot;\n&quot;</span>)
      <span class="dirc">#include</span> FileName
      <span class="obj">object</span><span class="squig">{</span>Surface<span class="squig">}</span>
   <span class="cond">#else</span>
      <span class="dirc">#local</span> NumVertices<span class="math">=</span>(PRes<span class="math">+</span><span class="num">1</span>)<span class="math">*</span>(ResSpl<span class="math">+</span><span class="num">1</span>);
      <span class="dirc">#local</span> NumFaces<span class="math">=</span>PRes<span class="math">*</span>ResSpl<span class="math">*</span><span class="num">2</span>;
      <span class="msg">#debug</span> <span class="func">concat</span>(<span class="str">&quot;\n Calculating &quot;</span>,<span class="func">str</span>(NumVertices,<span class="num">0</span>,<span class="num">0</span>),<span class="str">&quot; vertices for &quot;</span>, <span class="func">str</span>(NumFaces,<span class="num">0</span>,<span class="num">0</span>),<span class="str">&quot; triangles\n\n&quot;</span>)
      <span class="dirc">#local</span> VecArr<span class="math">=</span><span class="func">array</span>[NumVertices]
      <span class="dirc">#local</span> NormArr<span class="math">=</span><span class="func">array</span>[NumVertices]
      <span class="dirc">#local</span> UVArr<span class="math">=</span><span class="func">array</span>[NumVertices]
      <span class="dirc">#local</span> H<span class="math">=</span>PSpl(<span class="num">0</span>);
      <span class="dirc">#local</span> Scale<span class="math">=</span><span class="func">pow</span>( <span class="func">pow</span>(H<span class="num">.</span><span class="dot">x</span>,<span class="num">2</span>) <span class="math">+</span> <span class="func">pow</span>(H<span class="num">.</span><span class="dot">z</span>,<span class="num">2</span>), <span class="num">0.5</span>);
      <span class="dirc">#local</span> H<span class="math">=</span>H<span class="num">.</span><span class="dot">y</span>;
      <span class="dirc">#local</span> P<span class="math">=</span>Spl(<span class="num">0</span>);
      <span class="dirc">#local</span> P<span class="math">=</span><span class="func">pow</span>( <span class="func">pow</span>(P<span class="num">.</span><span class="dot">x</span>,<span class="num">2</span>) <span class="math">+</span> <span class="func">pow</span>(P<span class="num">.</span><span class="dot">z</span>,<span class="num">2</span>), <span class="num">0.5</span>);
      <span class="dirc">#local</span> Corr<span class="math">=</span>(P<span class="math">-</span>Scale);
      <span class="dirc">#local</span> IStep<span class="math">=</span><span class="num">1</span><span class="math">/</span>PRes;
      <span class="dirc">#local</span> JStep<span class="math">=</span><span class="num">1</span><span class="math">/</span>ResSpl;
      <span class="dirc">#local</span> Count<span class="math">=</span><span class="num">0</span>;
      <span class="dirc">#local</span> I<span class="math">=</span><span class="num">0</span>;
      <span class="cond">#while</span>(I<span class="math">&lt;</span><span class="math">=</span><span class="num">1</span>)
         <span class="dirc">#local</span> Scale0<span class="math">=</span>PSpl(I);
         <span class="dirc">#local</span> H0<span class="math">=</span><span class="math">&lt;</span><span class="num">0</span>,Scale0<span class="num">.</span><span class="dot">y</span><span class="math">-</span>H,<span class="num">0</span><span class="math">&gt;</span>;
         <span class="dirc">#local</span> Scale1<span class="math">=</span>PSpl(I<span class="math">+</span>IStep);
         <span class="dirc">#local</span> H1<span class="math">=</span><span class="math">&lt;</span><span class="num">0</span>,Scale1<span class="num">.</span><span class="dot">y</span><span class="math">-</span>H,<span class="num">0</span><span class="math">&gt;</span>;
         <span class="dirc">#local</span> Scale2<span class="math">=</span>PSpl(I<span class="math">-</span>IStep);
         <span class="dirc">#local</span> H2<span class="math">=</span><span class="math">&lt;</span><span class="num">0</span>,Scale2<span class="num">.</span><span class="dot">y</span><span class="math">-</span>H,<span class="num">0</span><span class="math">&gt;</span>;
         <span class="dirc">#local</span> Scale0<span class="math">=</span>RangeMM( <span class="func">pow</span>( <span class="func">pow</span>(Scale0<span class="num">.</span><span class="dot">x</span>,<span class="num">2</span>)<span class="math">+</span> <span class="func">pow</span>(Scale0<span class="num">.</span><span class="dot">z</span>,<span class="num">2</span>), <span class="num">0.5</span>)<span class="math">+</span>(Corr), <span class="num">0</span>,P,<span class="num">0</span>,<span class="num">1</span>);
         <span class="dirc">#local</span> Scale1<span class="math">=</span>RangeMM( <span class="func">pow</span>( <span class="func">pow</span>(Scale1<span class="num">.</span><span class="dot">x</span>,<span class="num">2</span>)<span class="math">+</span> <span class="func">pow</span>(Scale1<span class="num">.</span><span class="dot">z</span>,<span class="num">2</span>), <span class="num">0.5</span>)<span class="math">+</span>(Corr), <span class="num">0</span>,P,<span class="num">0</span>,<span class="num">1</span>);
         <span class="dirc">#local</span> Scale2<span class="math">=</span>RangeMM( <span class="func">pow</span>( <span class="func">pow</span>(Scale2<span class="num">.</span><span class="dot">x</span>,<span class="num">2</span>)<span class="math">+</span> <span class="func">pow</span>(Scale2<span class="num">.</span><span class="dot">z</span>,<span class="num">2</span>), <span class="num">0.5</span>)<span class="math">+</span>(Corr), <span class="num">0</span>,P,<span class="num">0</span>,<span class="num">1</span>);
         <span class="dirc">#local</span> J<span class="math">=</span><span class="num">0</span>;
         <span class="cond">#while</span> (J<span class="math">&lt;</span><span class="math">=</span><span class="num">1</span>)
            <span class="dirc">#local</span> P0<span class="math">=</span>(Spl(J)<span class="math">*</span>Scale0)<span class="math">+</span>H0;
            <span class="dirc">#local</span> P1<span class="math">=</span>(Spl(J)<span class="math">*</span>Scale1)<span class="math">+</span>H1;
            <span class="dirc">#local</span> P2<span class="math">=</span>(Spl(J)<span class="math">*</span>Scale2)<span class="math">+</span>H2;
            <span class="dirc">#local</span> P3<span class="math">=</span>(Spl(J<span class="math">+</span>JStep)<span class="math">*</span>Scale0)<span class="math">+</span>H0;
            <span class="dirc">#local</span> P4<span class="math">=</span>(Spl(J<span class="math">-</span>JStep)<span class="math">*</span>Scale0)<span class="math">+</span>H0;
            <span class="dirc">#local</span> B1<span class="math">=</span>P4<span class="math">-</span>P0;
            <span class="dirc">#local</span> B2<span class="math">=</span>P2<span class="math">-</span>P0;
            <span class="dirc">#local</span> B3<span class="math">=</span>P3<span class="math">-</span>P0;
            <span class="dirc">#local</span> B4<span class="math">=</span>P1<span class="math">-</span>P0;
            <span class="dirc">#local</span> N1<span class="math">=</span><span class="func">vcross</span>(B1,B2);
            <span class="dirc">#local</span> N2<span class="math">=</span><span class="func">vcross</span>(B2,B3);
            <span class="dirc">#local</span> N3<span class="math">=</span><span class="func">vcross</span>(B3,B4);
            <span class="dirc">#local</span> N4<span class="math">=</span><span class="func">vcross</span>(B4,B1);
            <span class="dirc">#local</span> Norm<span class="math">=</span><span class="func">vnormalize</span>((N1<span class="math">+</span>N2<span class="math">+</span>N3<span class="math">+</span>N4));
            <span class="dirc">#local</span> VecArr[Count]<span class="math">=</span>P0;
            <span class="dirc">#local</span> NormArr[Count]<span class="math">=</span>Norm;
            <span class="dirc">#local</span> UVArr[Count]<span class="math">=</span><span class="math">&lt;</span>J,I<span class="math">&gt;</span>;
            <span class="dirc">#local</span> J<span class="math">=</span>J<span class="math">+</span>JStep;
            <span class="dirc">#local</span> Count<span class="math">=</span>Count<span class="math">+</span><span class="num">1</span>;
         <span class="cond">#end</span>
         <span class="msg">#debug</span> <span class="func">concat</span>(<span class="str">&quot;\r Done &quot;</span>, <span class="func">str</span>(Count,<span class="num">0</span>,<span class="num">0</span>),<span class="str">&quot; vertices : &quot;</span>, <span class="func">str</span>(<span class="num">100</span><span class="math">*</span>Count<span class="math">/</span>NumVertices,<span class="num">0</span>,<span class="num">2</span>),<span class="str">&quot; %&quot;</span>)
         <span class="dirc">#local</span> I<span class="math">=</span>I<span class="math">+</span>IStep;
      <span class="cond">#end</span>
      BuildWriteMesh2(VecArr, NormArr, UVArr, ResSpl, PRes, FileName)
   <span class="cond">#end</span>
<span class="cond">#end</span>
</pre>
</body>
</html>